<?php

namespace Biz\model\MijiaSmartKitchen;

use Biz\pockets\modelTrait\BizModelTrait;
use Doraemon\pockets\datebase\BaseDbModel;

class MiJiaSmartKitchenPrize extends BaseDbModel
{
    const _CONFIG_FILE_ = 'db_store';

    const _CONFIG_SELECT_ = 'db_brand_activity';

    const _DATABASE_ = 'brand_activity';

    const _TABLE_NAME = 'mijia_smart_kitchen_prize';

    use BizModelTrait;


    /**
     * 减奖品库存
     * @param $prizeId
     * @param $stock
     * @param $version
     * @return bool|int
     */
    public static function dePrizeStock($prizeId, $stock, $version)
    {
        $where = [
            'id' => $prizeId,
            'stock[>]' => 0,
            'stock_version' => $version,
            'data_status' => self::STATUS_NORMAL
        ];
        $data = [
            'stock' => --$stock,
            'stock_version' => ++$version,
            'update_tieme' => date('Y-m-d H:i:s', time())
        ];
        return self::dataUpdate($data, $where, true);
    }

}